1. Field of the Invention
The present invention generally relates to the conversion of data from one type to another type in computer software and, more particularly, to a generalized mechanism to manage ad-hoc type conversions in computer software.
2. Background Description
Converting data from one type, e.g., a string, to another type, e.g., a color, is a very common operation in computer software. An extremely common occurrence of this is when accepting an input in a graphical user interface (GUI) via a text field for a non-string data item such as a number.
Several categories of type conversions can be identified:
automatic type converts, where the language processor automatically converts a value of one type to be of another type by applying some conversion logic built-in to the language processor. This may be done for primitive types as well as for object types. In object systems, such conversions are limited to upward type converts in the underlying type lattice.
user-requested type converts, where the user (i.e., the application programmer) directs the compiler to convert a value of one type to be that of another type by applying either a static, user-defined or built-in convertor. This may be done for primitive types as well as object types.
ad-hoc type converts, where unrelated types of objects are converted using ad-hoc mechanisms, e.g., a string to a font. These are currently explicitly managed by the user (i.e., the application programmer versus the xe2x80x9csystemxe2x80x9d (i.e., the language processor) programmer) by writing appropriate functions and invoking them as needed on an ad-hoc basis. In some cases, certain type conversions may be supported by library functions (e.g., converting from a string to an integer value).
As software development evolves towards the composition of off-the-shelf components, ad-hoc type conversions become ubiquitous. The current approach is very much oriented around a single programmer or programming project managing their own type conversion needs. The problem with this strategy is that it does not scale with large projects nor over time, and tends not to encourage the construction of reusable type convertors.
It is therefore an object of the present invention to provide a generalized mechanism to manage ad-hoc type conversions in computer software.
According to the invention, there is provided a management framework that separates the task of defining individual type converters from the task of locating type converters on demand. This separation is achieved by the introduction of a xe2x80x9ctype converter registryxe2x80x9d. Type converters are added to the registry once they are defined in order to make them available for future use. Later on, type converters are retrieved on demand, by searching them in the registry according to a unique identification key.
This invention encourages and facilitates the reuse of component-oriented type conversions. It makes possible to distribute the usage of the management mechanism to either the application or the system (language processor) level. Finally, it enables run-time redefinition of the conversion algorithms (as opposed to statically defined conversions in the C++ language).